using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mgh.Data.Sql;
using Jewelry.BussinessLayer;
using Jewelry.Entities;

public partial class Pages_UPayment : Mgh.UI.Sql.PageBase
{
    #region properties

    private DataSources.Jw_Tbl_PaymentDataTable Payment
    {
        get {return Session["payment"] == null ? null : Session["payment"] as DataSources.Jw_Tbl_PaymentDataTable; }
        set { Session["payment"] = value; }
    }

    #endregion

    #region events

    override protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!CurrentUser.checkUser())
            Response.Redirect("ULogin.aspx?url=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
        if (!IsPostBack)
        {
            bindData();
        }
    }

    protected void btSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Payment = this.prepairData();
            Response.Redirect("UShipment.aspx");
        }
    }

    #endregion

    #region functions

    private DataSources.Jw_Tbl_PaymentDataTable prepairData()
    {
        DataSources.Jw_Tbl_PaymentDataTable tb = new DataSources.Jw_Tbl_PaymentDataTable();
        DataSources.Jw_Tbl_PaymentRow row = tb.NewJw_Tbl_PaymentRow();
        row.LoaiThanhToan = dlLoai.SelectedValue;
        row.LoaiThe = dlLoaiThe.SelectedValue;
        row.MaSoThe = TextBox1.Text;
        row.MatMa = TextBox2.Text;
        row.BatDau = System.DateTime.Now;
        row.TrangThai = "Processing";
        row.OrID = string.Empty;
        tb.AddJw_Tbl_PaymentRow(row);
        return tb;
    }

    private void bindData()
    {
        if (Payment != null && Payment.Count > 0)
        {
            dlLoai.SelectedValue = Payment[0].IsLoaiThanhToanNull() ? string.Empty : Payment[0].LoaiThanhToan;
            dlLoaiThe.SelectedValue = Payment[0].IsLoaiTheNull()?string.Empty: Payment[0].LoaiThe;
            TextBox1.Text = Payment[0].IsMaSoTheNull() ? string.Empty : Payment[0].MaSoThe;
            TextBox2.Text = Payment[0].IsMatMaNull() ? string.Empty : Payment[0].MatMa;
            TextBox3.Text = TextBox2.Text;
        }
    }

    #endregion
}
